#include "knight.h"
#include "src/move.h"
#include "src/constants.h"

Knight::Knight( int x, int y, QString pixmap_path, int color, QGraphicsItem* parent ) : BoardFigure( x, y, pixmap_path, color, parent )
{
}

QList<Move*>& Knight::getPossibleMoves( BoardFigure* board[8][8] ) {
  qDebug() << "Knight GetPossibleMoves called";

  if ( possibleMovesReady ) return possibleMoves;

  int dx[] = { -2, -2, -1, -1,  1,  1,  2, 2 };
  int dy[] = { -1,  1, -2,  2, -2,  2, -1, 1 };

  for ( int i=0; i < 8; i++ ) {
    int newX = getBoardX() + dx[i];
    int newY = getBoardY() + dy[i];
    if ( checkNewPos( newX, newY )
         && ( board[newX][newY] == 0 || board[newX][newY]->getColor() != getColor() )
         ) {
      Move* move = new Move( getBoardX(), getBoardY(), newX, newY );
      possibleMoves.push_back( move );
    }
  }

  possibleMovesReady = true;
  return possibleMoves;
}
